home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
CONTAINER
/
Iterator.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-06-18
|
2KB
|
85 lines
#ifndef Iterator_First
#ifdef __GNUG__
//pragma once
#pragma interface
#endif
#define Iterator_First
#include "Types.h"
#include "Storage.h"
class Container;
class Object;
//---- IteratorBase ------------------------------------------------------------
class IteratorBase {
#ifdef __GNUG__
char *dummy; // g++ warns about empty classes !!
#endif
protected:
IteratorBase() { };
public:
virtual ~IteratorBase() { };
virtual Object *operator()();
virtual void Reset();
//---- memory allocation
void *operator new (size_t sz)
{ return Storage::ChunkAlloc(sz); }
void operator delete(void *vp)
{ Storage::ChunkFree(vp); }
};
//---- Iterator ----------------------------------------------------------------
class Iterator : public IteratorBase {
friend Container;
protected:
Iterator();
public:
~Iterator();
void Reset();
protected:
//---- support for robust Iterators
bool IsActive() { return (started && ! terminated); };
bool Start(); // for non-derived classes private
void Terminate(); // for non-derived classes private
virtual Container *GetContainer();
//---- support for robust iterators - events signaled from container
virtual void AboutToDie(void *ignored= 0);
virtual void AboutToAdd(void *position);
virtual void AboutToRemove(void *position);
virtual void AboutToEmpty(void *ignored= 0);
virtual void SavePosition(void *ignored= 0);
virtual void ResetPosition(void *ignored= 0);
protected:
bool Started() { return started; };
bool Terminated() { return terminated; };
static void (Iterator::*aboutToEmpty)(void *); // ??
private:
//---- only used by Container
void ChainIn(Iterator *anchor);
void ChainOut();
void Init() { next= this; prev= this; };
private:
bool started, terminated;
Iterator *next, *prev; // linking iterators - only used by Container
};
//---- Iterator0 ---------------------------------------------------------------
class Iterator0 : public Iterator {
public:
Iterator0();
Object *operator()();
void Reset();
};
#endif